var API = API || {};

$(function() {

    // Custom combox
    $('.dropdownized').dropdownized();

    // Language menu hover
    $('#right_menu li, #right_menu li a').hoverIntent(
            function() {
                $(this).children('ul').fadeIn('fast');
            },
            function() {
                $(this).children('ul').fadeOut('fast');
            }
    );

    var browser = {
        chrome: false,
        mozilla: false,
        opera: false,
        msie: false,
        safari: false
    };
    var sBrowser, sUsrAg = navigator.userAgent;
    if (sUsrAg.indexOf("Chrome") > -1) {
        browser.chrome = true;
    } else if (sUsrAg.indexOf("Safari") > -1) {
        browser.safari = true;
    } else if (sUsrAg.indexOf("Opera") > -1) {
        browser.opera = true;
    } else if (sUsrAg.indexOf("Firefox") > -1) {
        browser.mozilla = true;
    } else if (sUsrAg.indexOf("MSIE") > -1) {
        browser.msie = true;
    }

    if (browser.mozilla) {
        //$('nav li:last-child a').css('padding', '9px 2.193em');
    }

    subscribe_submit = function() {

        $('#subscribe_form button').attr('disabled', 'disabled');

//        $("#subscribe").mask(APID.Data.lang['dtl_subscribing'] + "...");


        form = $('#subscribe_form');
        var serialize = form.serialize();

        $.ajax({
            url: API.Data.lang_url + '/subscribe?' + serialize + '&ajax=true',
            method: 'get',
            success: function(data) {
//                $("#subscribe").unmask();

                if (data == 0) {
                    alert(API.Data.lang['dtl_subscribe_alredy']);
                    $('#subscribe_form button').removeAttr('disabled');

                } else {
                    alert(API.Data.lang['dtl_subscribe_thanks']);

                }

            }
        });
    };

    $('#subscribe_form').validate({
        errorElement: "em",
        submitHandler: subscribe_submit
    });

    $('#lang_select').on('change', function() {
        window.location = $(this).val();
    });



});


